import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  }
]

export const asyncRoutes = [
  {
    path: '/product',
    component: Layout,
    redirect: '/product/list',
    name: 'Product',
    meta: { title: '商品管理', icon: 'shopping', roles: ['admin'] },
    children: [
      {
        path: 'list',
        name: 'ProductList',
        component: () => import('@/views/product/list'),
        meta: { title: '商品列表' }
      },
      {
        path: 'category',
        name: 'Category',
        component: () => import('@/views/product/category'),
        meta: { title: '商品分类' }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    children: [
      {
        path: 'list',
        name: 'OrderList',
        component: () => import('@/views/order/list'),
        meta: { title: '订单管理', icon: 'order' }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    children: [
      {
        path: 'list',
        name: 'UserList',
        component: () => import('@/views/user/list'),
        meta: { title: '用户管理', icon: 'user' }
      }
    ]
  },
  {
    path: '/news',
    component: Layout,
    children: [
      {
        path: 'list',
        name: 'NewsList',
        component: () => import('@/views/news/list'),
        meta: { title: '生活资讯', icon: 'news' }
      }
    ]
  },
  {
    path: '/shop',
    component: Layout,
    children: [
      {
        path: 'list',
        name: 'ShopList',
        component: () => import('@/views/shop/list'),
        meta: { title: '店铺管理', icon: 'shop' }
      }
    ]
  }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router 